package com.sxdx.service.impl;

import java.util.List;
import javax.annotation.Resource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import com.sxdx.dao.TeacherDAO;
import com.sxdx.entity.Teacher;
import com.sxdx.service.TeacherService;

@SuppressWarnings("all")
@Service("teacherService")
public class TeacherServiceImpl implements TeacherService {
	private static Logger logger = LogManager.getLogger(Thread.currentThread().getStackTrace()[1].getClassName());
	@Resource(name = "teacherDAO")
	private TeacherDAO teacherDAO;

	public void save(Teacher teacher) {
		teacherDAO.save(teacher);
	}

	public Teacher confirm(String username, String password) {
		if (!"".equals(username) && null != username) {
			if (!"".equals(password) && null != password) {
				String hql = "from Teacher t where t.username =?";
				String[] param = { username };
				Teacher t = teacherDAO.get(hql, param);
				if (t != null) {
					if (password.equals(t.getPassword())) {
						logger.trace("登录成功");
						return t;
					} else {
						logger.trace("密码不正确");
					}
				} else {
					logger.trace("该用户不存在");
				}
			} else {
				logger.trace("密码不为空");
			}
		} else {
			logger.trace("用户名不为空");
		}
		return null;
	}

	public List<Teacher> info(String hql, int page, int rows) {
		return teacherDAO.page(hql, page, rows);
	}

	public void delete(int id) {
		teacherDAO.delete(teacherDAO.get(Teacher.class, id));
	}

	public int findall() {
		return teacherDAO.find("from Teacher").size();
	}

	public void updatepassword(String username, String password, String newpassword) {
	}
}
